﻿using System;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using SLS.ExClassLib.Database;
using SLS.ExClassLib.Event;
using SLS.ExClassLib.DataType;
using SLS.ExClassLib.Message;
using SLS.ExClassLib.Events;
using SLS.ExClassLib.Data;
namespace SLS.Base
{
    public partial class ExQUERY
    {
        public CollectionViewSource vwQueryCond
        {
            get
            {
                return (CollectionViewSource)(TryFindResource("vwBaseQueryCond"));
            }
        }
        public override void CMDEXE_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            { 
                base.CMDEXE_TextChanged(sender, e);
            }
            catch (Exception ex)
            {
                throw;
            }

        }
        public override ExDataRow commandNew(string SM, string KEYDEFTYPE, string GTPRE, string GTKEY, string KEYINSTANCETABLE)
        {
            ExDataRow row = null;
            try
            {
                row = base.commandNew(SM, KEYDEFTYPE, GTPRE, GTKEY, KEYINSTANCETABLE);
            }
            catch (Exception ex)
            {
                throw;
            }
            return row;
        }
        public override ExDataRow commandCopy(ExDataRow dwThis)
        {
            ExDataRow row = null;
            try
            {
                row = base.commandCopy(dwThis);
            }
            catch (Exception ex)
            {
                throw;
            }
            return row;
        }
        public override void commandDelete(ExDataRow dwThis)
        {
            try
            {
                base.commandDelete(dwThis);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public override void commandModify(ExDataRow dwThis)
        {
            try
            {
                base.commandModify(dwThis);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public override void commandInformation(ExDataRow dwThis)
        {
            try
            {
                base.commandInformation(dwThis);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public override void commandSave(ExDataRow dwThis)
        {
            try
            {
                 dwThis.OnSaveRecord(1); 
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public void btnRefreshQueryCond_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DataRow dwTemp = ViewDataSet.SetQuery.Tables[TableQueryCond].NewRow();
                dwTemp["QueryType"] = "QueryOnly";
                dwTemp["CONDTYPE"] = "DB_" + TableQueryCond + "_SELECT_ALL";
                DataSet setRequest = new DataSet();
                setRequest = (DataSet)DataAccessService.Instance.ImportDataTable(setRequest, dwTemp);
                setRequest.DataSetName = TableQueryCond;

                ExDataSet setReturn = ExRowBase.QueryAndCreateData(setRequest, dwTemp);

                SetUQ.Tables[TableQueryCond].Clear();
                SetUQ.Merge(setReturn);
                vwBaseQueryCond.View.MoveCurrentToFirst();
            }
            catch (Exception ex)
            {
                Tracer.Error("LanSunStudio.Client.MainWindow:btnQuery_Click", ex);
            }
        }
        public void btnQuery_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DataSet setEvent = new DataSet();
                if (vwBaseQueryCond.View == null)
                    return;
                DataRow dwThis = ((DataRowView)vwQueryCond.View.CurrentItem).Row;
                if (dwThis == null)
                    return;
                MessageEx msg = new MessageEx();
                msg.JobID = "OnFileQuery";
                msg.Tag = BaseTable;
                setEvent = (DataSet)DataAccessService.Instance.ImportDataTable(setEvent, dwThis);
                msg.setEvent = setEvent;
                DataSet setReturn = DataAccessService.Instance.QueryData(msg);
                SetUI.Tables[BaseTable].Clear();
                SetUI.Merge(setReturn);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }
}
